package com.base.system.managedBean;

import java.io.Serializable;
import java.util.List;

import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.DataModel;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.grid.impl.UIDataGrid;

import com.base.commons.SpringBeanHolder;
import com.base.security.entity.SecurityRole;
import com.base.security.service.SecurityEntityManager;

/**
 * 
 * This managed bean is generated automatically
 */
@ManagedBean(name = "system_roleListOfOnePersonBean", scope = ManagedBeanScope.REQUEST)
public class RoleListOfOnePersonBean implements Serializable {
	private final static Log logger = LogFactory
			.getLog(DepartmentListOfOnePersonBean.class);
	protected SecurityEntityManager securityEntityManager = SpringBeanHolder
			.getBean("securityEntityManager");
	@Inject
	private FacesContext context;

	@Bind(id = "securityRoleListGrid", attribute = "binding")
	private UIDataGrid securityRoleListGrid;
	@SaveState
	private String userId;

	// @DataModel(id = "securityRoleGrid")
	// private List<SecurityRole> data = new LinkedList<SecurityRole>();
	@DataModel(id = "securityRoleListGrid")
	private List<SecurityRole> getSecurityRoleGrid() {
		return this.securityEntityManager.getUserRoles(userId);
	}

	@BeforeRender
	public void beforeRender(boolean isPostback) {
		logger.debug("Listbean 中的 postBack:" + isPostback);
		userId = context.getExternalContext().getRequestParameterMap().get(
				"userId");
	}
}
